package com.zr.inquiry.mapper;

import com.zr.inquiry.model.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * Created by lenovo on 2019/12/27.
 */
@Mapper
public interface InquiryMapper {
    int queryMaterialCount(MaterialSelectVo materialSelectVo);

    List<InquiryVo> queryMaterialData(MaterialSelectVo materialSelectVo);



    @Select("SELECT * from supplier s left join legalperson_supplier ls on s.partnerCode=ls.partnerCode left join legalPerson l on ls.legalPersonCode=l.legalPersonCode where l.legalPersonId=#{legalPersonId}")
    List<SupplierVo> queryByLegalPerson(Integer legalPersonId);

    int queryPartnerCount(SupplierSelectVo supplierSelectVo);

    List<SupplierVo> queryPartnerData(SupplierSelectVo supplierSelectVo);

    List<String> querySpareByCodeList(List<String> codeList);

    @Select("select count(legalPersonId) from legalperson where legalPersonId=#{legalPersonId}")
    int queryLegalPersonById( Integer legalPersonId);

    List<InquirySpareSupplierVo> querySpareSupplier(List<String> codeList);

    void insertSupplierDatail(@NotEmpty(message = "供应商信息不能为空！") @Valid List<InquirySupplierVo> supplierDetailsList);

    void insertSpareDetail(List<InquirySpareCodeVo> inquiryDetailsList);

    /*@Insert("insert into inquirytotal(requestForQuotationId,currencyCode,inquiryStatus,legalPersonId,typre,isTax,startTime,endTime,creatorName,createTime,updateName,updateTime,auditorName,ausitorExplain,auditorStatus,auditorTime,approverName,approverStatus,approverTime) values (#{requestForQuotationId},#{currencyCode},#{inquiryStatus},#{legalPersonId},#{typre},#{isTax},#{startTime},#{endTime},#{creatorName},#{createTime},#{updateName},#{updateTime},#{auditorName},#{ausitorExplain},#{auditorStatus},#{auditorTime},#{approverName},#{approverStatus},#{approverTime})")*/
    void inserTotal(InquiryVo inquiryVo);


    List<InquiryVo> queryAllInquiry(InquiryServiceVo inquiryServiceVo);

    int queryAllInquiryCount(InquiryServiceVo inquiryServiceVo);

    @Update("update inquirytotal set currencyCode=#{currencyCode},inquiryStatus=#{inquiryStatus},legalPersonId=#{legalPersonId}," +
            "type=#{type},isTax=#{isTax},startTime=#{startTime},endTime=#{endTime},updateName=#{updateName},updateTime=#{updateTime} " +
            "where requestForQuotationId=#{requestForQuotationId}")
    void updateTotal(InquiryVo inquiryVo);
    @Delete("delete from inquirysparedetail where inquiryId=#{id}")
    void deleteBySpareDetailInquirtId(Integer id);
    @Delete("delete from inquirysupplierdetail where inquiryId=#{id}")
    void deleteBySupplierDetailInquirtId(Integer id);

    void insertSupplierDetail(@NotEmpty(message = "供应商信息不能为空！") @Valid List<InquirySupplierVo> supplierDetailsList);
    @Select("select * from inquirysparedetail where inquiryId=#{id}")
    List<InquirySpareCodeVo> querySpareByInquoryId(Integer id);

    @Select("select i.*,l.legalPersonName from inquirytotal i left join legalperson l on i.legalPersonId = l.legalPersonId where i.requestForQuotationId=#{requestForQuotationId}")
    InquiryVo queryInquiryByForQquotationId(String requestForQuotationId);
    @Select("select * from inquirysupplierdetail where inquiryId=#{id}")
    List<InquirySupplierVo> querySupplierByInquoryId(Integer id);



}
